<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>家居家具管理系统</title>

    <!-- begin::global styles -->
    <link rel="stylesheet" href="${APP_PATH}/assets/vendors/bundle.css" type="text/css">
    <!-- end::global styles -->


    <!-- begin::dropzone -->
    <link rel="stylesheet" href="${APP_PATH}/assets/vendors/dropzone/dropzone.css" type="text/css">
    <!-- begin::dropzone -->

    <!-- begin::custom styles -->
    <link rel="stylesheet" href="${APP_PATH}/assets/css/app.css" type="text/css">
    <link rel="stylesheet" href="${APP_PATH}/assets/css/custom.css" type="text/css">
    <!-- end::custom styles -->

</head>
<body>

<!-- begin::page loader-->
<div class="page-loader">
    <div class="spinner-border text-success"></div>
    <span>加载中 ...</span>
</div>
<!-- end::page loader -->



<!-- begin::navigation -->
<jsp:include page="/WEB-INF/jsps/Manager/common/navigation.jsp"/>
<!-- end::navigation -->

<!-- begin::top -->
<jsp:include page="/WEB-INF/jsps/Manager/common/top.jsp"/>
<!-- end::top -->

<!-- begin::main content -->
<main class="main-content">

    <div class="container-fluid">

        <!-- begin::page header -->
        <div class="page-header d-md-flex justify-content-between align-items-center">
            <h4>修改密码</h4>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb m-t-0">
                    <li class="breadcrumb-item"><a href="${APP_PATH}/toManager">首页</a></li>
                    <li class="breadcrumb-item"><a href="${APP_PATH}/toAdminInfo">个人中心</a></li>
                    <li class="breadcrumb-item active" aria-current="page">修改密码</li>
                </ol>
            </nav>
        </div>
        <!-- end::page header -->


        <div class="card">
            <div class="card-body">
                <h5 class="card-title">请设置密码</h5>
                <form id="updateApass" >
                    <input type="hidden" name="aid" value="${sessionScope.admin.aid}"/>
                    <div class="form-group">
                        <label for="oldPass">原密码</label>
                        <input type="password" class="form-control" id="oldPass" aria-describedby="oldPassHelp" >
                        <small id="oldPassHelp" class="form-text text-muted">请输入原始密码</small>
                    </div>
                    <div class="form-group">
                        <label for="newPass">新密码</label>
                        <input type="password" class="form-control" id="newPass" name="apass" aria-describedby="newPassHelp">
                        <small id="newPassHelp" class="form-text text-muted">请输入新密码</small>
                    </div>
                    <div class="form-group">
                        <label for="newPass1">确认密码</label>
                        <input type="password" class="form-control" id="newPass1" aria-describedby="newPass1Help">
                        <small id="newPass1Help" class="form-text text-muted">请再次输入新密码</small>
                    </div>
                    <input type="submit" onclick="return checkApass()" class="btn btn-primary" value="确定">
                </form>
            </div>
        </div>




        <!-- begin::bottom -->
        <div class="card-group">
            <jsp:include page="/WEB-INF/jsps/Manager/common/bottom.jsp"/>
        </div>
        <!-- end::bottom -->

    </div>

</main>
<!-- end::main content -->

<!-- begin::global scripts -->
<script src="${APP_PATH}/assets/vendors/bundle.js"></script>
<!-- end::global scripts -->



<!-- begin::custom scripts -->
<script src="${APP_PATH}/assets/js/custom.js"></script>
<script src="${APP_PATH}/assets/js/app.js"></script>
<!-- end::custom scripts -->
<script>
    function checkApass() {
        var flag = true;
        if($("#oldPass").val() =='' || $("#newPass").val() =='' || $("#newPass1").val() ==''){
            flag = false;
            swal("设置密码未完成！", {icon: "error"});
        }else{
            if('${sessionScope.admin.apass}' != $("#oldPass").val()){
                flag = false;
                swal("原始密码错误！", {icon: "error"});
            }
            if($("#newPass").val() != $("#newPass1").val()){
                flag = false;
                swal("两次密码不一致！", {icon: "error"});
            }
        }

        if(flag){
            $.ajax({
                url : "${APP_PATH}/admin/updateApass",
                method : "POST",
                data : $("#updateApass").serialize(),
                success : function (result) {
                    if(result.success){
                        swal("修改成功！", {icon: "success"}).then((value) => {
                            window.location.href = '${APP_PATH}/toManagerLogin';
                    });
                    }
                }
            });
        }
       return false;
    }
</script>


</body>
</html>
